package com.ssd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ssd.entity.VmTypeEntity;
import com.ssd.mapper.VMTypeDao;
import com.ssd.service.VMTypeService;
import com.ssd.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.Map;

@Service
public class VMTypeServiceImpl extends ServiceImpl<VMTypeDao, VmTypeEntity> implements VMTypeService {

    @Autowired
    private VMTypeDao vmTypeDao;

    /**
     * 分页查询商品列表，支持模糊查询
     *
     * @param pageNum  当前页码
     * @param pageSize 每页大小
     * @return 分页的商品集合
     */
    @Override
    public Page<VmTypeEntity> getVMTypeList(int pageNum, int pageSize,String typeName) {
        // 创建分页对象
        Page<VmTypeEntity> page = new Page<>(pageNum, pageSize);

        // 构建查询条件
        LambdaQueryWrapper<VmTypeEntity> wrapper = new LambdaQueryWrapper<>();

        // 如果 typeName 不为空，则添加查询条件
        if (StringUtils.isNotEmpty(typeName)) {
            wrapper.like(VmTypeEntity::getName, typeName); // 使用模糊匹配
        }

        // 执行查询并返回结果
        return vmTypeDao.selectPage(page, wrapper);
    }

    @Override
    public VmTypeEntity selectVmTypeById(Long id) {
        return vmTypeDao.selectById(id);
    }

    @Override
    public int insertVmType(VmTypeEntity vmType) {
        return vmTypeDao.insert(vmType);
    }

    @Override
    public int updateVmType(VmTypeEntity vmType) {
        return vmTypeDao.updateById(vmType);
    }

    @Override
    public int deleteVmTypeById(Long[] vmIds) {
        return vmTypeDao.deleteBatchIds(java.util.Arrays.asList(vmIds));
    }


}